package values.item
{
import core.Configuration;

import framework.view.components.graphics.SWF;

import mx.utils.StringUtil;

public class ItemAssetValue
{
	private static const XML_PATTERN:String = "<asset direction=\"{1}\" url=\"{2}\" classRef=\"{3}\" is_default=\"{4}\" />"
		
	public function ItemAssetValue()
	{
	}
	
	[Data(type="field", mapping="@direction")]
	public var direction:String;
	
	[Data(type="field", mapping="@url")]
	public var baseUrl:String;
	
	public function get url():String
	{
		return Configuration.assetsPath + baseUrl;
	}
	
	[Data(type="field", mapping="@classRef")]
	public var classRef:String;
	
	[Data(type="field", mapping="@is_default")]
	public var isDefault:Boolean = false;
	
	public function get assetMode():String
	{
		var mode:String = SWF.SINGLE;
		if (classRef && classRef != "")
		{
			mode = SWF.EXTERNAL_LIBS;
		}
		return mode;
	}
	
	public function get isSWF():Boolean
	{
		return url.indexOf(".swf") > 0;
	}
	
	public function clone():ItemAssetValue
	{
		var vo:ItemAssetValue = new ItemAssetValue();
		vo.direction = direction;
		vo.baseUrl = baseUrl;
		vo.classRef = classRef;
		vo.isDefault = isDefault;
		return vo;
	}
	
	public function generateXML():XML
	{
		var xmlStr:String = StringUtil.substitute(XML_PATTERN, 
												  this.direction,
												  this.direction,
												  this.baseUrl,
												  this.classRef,
												  this.isDefault);
		var xml:XML = new XML(xmlStr);
		return xml;
	}

}
}